<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user_recipe_record".
 *
 * @property int $id
 * @property int $user_id 用户id
 * @property int $user_secondary_id 次级用户id
 * @property int $user_recipe_id 用户处方id
 * @property int $num 药品数量
 * @property string $price 价格(药品总价)
 * @property string $create_time 操作日期
 * @property int $status 状态
 *
 * @property User $user
 * @property UserSecondary $userSecondary
 * @property UserRecipe $userRecipe
 */
class UserRecipeRecord extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_recipe_record';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'user_recipe_id'], 'required'],
            [['user_id', 'user_secondary_id', 'user_recipe_id', 'num', 'status'], 'integer'],
            [['create_time'], 'safe'],
//            [['price'], 'string', 'max' => 20],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
            [['user_secondary_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserSecondary::className(), 'targetAttribute' => ['user_secondary_id' => 'id']],
            [['user_recipe_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserRecipe::className(), 'targetAttribute' => ['user_recipe_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户id',
            'user_secondary_id' => '次级用户id',
            'user_recipe_id' => '用户处方id',
            'num' => '药品数量',
            'price' => '价格(药品总价)',
            'create_time' => '操作日期',
            'status' => '状态',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserSecondary()
    {
        return $this->hasOne(UserSecondary::className(), ['id' => 'user_secondary_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserRecipe()
    {
        return $this->hasOne(UserRecipe::className(), ['id' => 'user_recipe_id']);
    }
}
